package model;

import entities.ViewScheduler;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.table.AbstractTableModel;

public class ViewSchedulerTableModel extends AbstractTableModel {

    private ArrayList<ViewScheduler> list;
    private static SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/YYYY");

    public ViewSchedulerTableModel() {
        list = new ArrayList<ViewScheduler>();
    }

    public ViewSchedulerTableModel(ArrayList<ViewScheduler> list) {
        this.list = list;
    }

    @Override
    public int getRowCount() {
        return list.size();
    }

    @Override
    public int getColumnCount() {
        return 4;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        ViewScheduler record = list.get(rowIndex);
        Date endDate = record.getEndDate();
        switch (columnIndex) {
            case 0:
                return record.getDepartmentName();
            case 1:
                return record.getShiftName();
            case 2:
                return dateFormat.format(record.getStartDate());
            case 3:
                if(endDate != null) {
                    return dateFormat.format(endDate);
                }
                return "";
            default:
                return null;
        }
    }

    @Override
    public String getColumnName(int column) {
        switch (column) {
            case 0:
                return "Department";
            case 1:
                return "Shift";
            case 2:
                return "StartDate";
            case 3:
                return "EndDate";
            default:
                return null;
        }
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        switch (columnIndex) {
            case 0:
                return String.class;
            case 1:
                return Integer.class;
            case 2:
                return String.class;
            case 3:
                return String.class;
            default:
                return null;
        }
    }
}
